<!--
* @description  : 案件-抽样取证物品清单
* @descriptionDetail: 案件-抽样取证物品清单
* @copyright    : 浙江烟草
* @author       : sy
* @create       : 2022-10-31 16:21:34
-->
<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999">
      <view class="nav-right-icon" @click="printOrDown(state.canEdit)">
        {{ state.canEdit?'预览':'打印' }}
      </view>
    </theme-navbar>
    <!-- #endif -->
		<!-- #ifdef H5-WECHAT || H5-EMP -->
		<fab-button :content="state.canEdit?fContent:fContents" @fabtrigger="fabtrigger" />
		<!-- #endif -->
    <view class="main-content">
      <view style="width: calc(100% + 30px);">
        <form-section title="抽样取证物品清单"></form-section>
      </view>
      <u-form
        :model="sampleForm"
        :error-type="errorType"
        :rules="rules"
        class="form-content"
        ref="uForm"
      >
        <u-form-item
          label="立案编号"
          :required="isRequired"
          :label-position="labelPosition"
          prop="caseCode"
        >
          <u-input v-model="sampleForm.caseCode" />
        </u-form-item>
        <u-form-item
          label="当事人"
          :required="isRequired"
          :label-position="labelPosition"
          prop="party"
          right-icon="arrow-right"
        >
          <u-input
            :disabled="true"
            v-model="sampleForm.party"
            @click="
              () => {
                if (state.canEdit) partySelectShow = true;
              }
            "
          />
        </u-form-item>
        <u-form-item
          label="抽样时间"
          :required="isRequired"
          prop="sampleDate"
          right-icon="arrow-right"
          :label-width="labelWidth"
          ref="changeRefS"
        >
          <u-input
            placeholder="请输入抽样时间"
            input-align="right"
            :disabled="true"
            :clearable="false"
            v-model="sampleForm.sampleDate"
            @click="
              () => {
                state.canEdit && clickDateBtn('time');
              }
            "
          />

        </u-form-item>
        <u-form-item
          label="抽样方法"
          :required="isRequired"
          :label-position="labelPosition"
          prop="samplingFun"
        >
          <dic-input
            :keyWord="$u.dic.DIC_KEYS.SAMPLE_STYLE"
            :dicCode="sampleForm.samplingFun"
            inputAlign="left"
            type="select"
            :select-open="
              dicSelectOpen('samplingFun', $u.dic.DIC_KEYS.SAMPLE_STYLE)
            "
            placeholder="请选择"
            v-model="sampleForm.samplingFunName"
            @changeInputModelData="
              (name) => {
                $set(sampleForm, 'samplingFunName', name);
              }
            "
            @click="
              showDic(
                $u.dic.DIC_KEYS.SAMPLE_STYLE,
                sampleForm.samplingFun,
                'samplingFun'
              )
            "
          />
        </u-form-item>
        <u-form-item
          label="送达方式"
          :required="isRequired"
          :label-position="labelPosition"
          prop="deliveryStyle"
        >
          <dic-input
            :keyWord="$u.dic.DIC_KEYS.BSC_SERVICE_TYPE"
            :dicCode="sampleForm.deliveryStyle"
            inputAlign="left"
            type="select"
            :select-open="
              dicSelectOpen('deliveryStyle', $u.dic.DIC_KEYS.BSC_SERVICE_TYPE)
            "
            placeholder="请选择"
            v-model="sampleForm.deliveryStyleName"
            @changeInputModelData="
              (name) => {
                $set(sampleForm, 'deliveryStyleName', name);
              }
            "
            @click="
              showDic(
                $u.dic.DIC_KEYS.BSC_SERVICE_TYPE,
                sampleForm.deliveryStyle,
                'deliveryStyle'
              )
            "
          />
        </u-form-item>
        <u-form-item
          label="抽样目的"
          :required="isRequired"
          :label-position="labelPosition"
          prop="sampleDest"
        >
          <u-input :disabled="!state.canEdit" v-model="sampleForm.sampleDest" />
        </u-form-item>
        <u-form-item
          label="抽样地点"
          :required="isRequired"
          prop="address"
          :label-position="labelPosition"
        >
          <u-input
            placeholder="请输入抽样地点"
            :disabled="!state.canEdit"
            v-model="sampleForm.address"
          />
        </u-form-item>
        <u-form-item
          label="文书日期"
          label-width="200"
          right-icon="arrow-right"
          :required="true"
          ref="docDateChangeRef"
        >
          <u-input
            :disabled="true"
            input-align="right"
            placeholder="请选择日期"
	          :custom-style="pointerStyle"
            v-model="sampleForm.docDate"
            @click="
              () => {
                state.canEdit && (isShowDocDate = true);
              }
            "
          />
        </u-form-item>
        <u-form-item
          label="送达地点"
          label-width="200"
          :required="true"
          prop="deliveryAddr"
        >
          <u-input
            type="textarea"
            placeholder="请输入送达地点"
            v-model="sampleForm.deliveryAddr"
          />
        </u-form-item>
        <u-form-item ref="personChangeRef">
          <view class="person-info">
            <view class="p-title">
              <view class="doc-sub-required">
                *
              </view>
              <view class="doc-sub-title">
                承办人
              </view>
              <view class="uicon-sty" @click="docSub(state.canEdit)">
                <u-icon
                  name="plus-circle"
                  :color="$theme.u_type_primary"
                  size="40"
                ></u-icon>
              </view>
            </view>
            <u-input
              placeholder="请输入"
              type="textarea"
              height="100"
              :auto-height="true"
              :disabled="true"
              v-model="sampleForm.undertaker"
            />
          </view>
        </u-form-item>
        <u-form-item
          :label-position="labelPosition"
          label="备注"
          prop="remark"
          :border-bottom="false"
        >
          <u-input
            type="textarea"
            placeholder="请填写备注"
            :maxlength="maxLength"
            :disabled="!state.canEdit"
            v-model="sampleForm.remark"
          />
        </u-form-item>
        <view style="margin: -6px -16px 0px -16px">
          <u-gap
            :height="$theme.cm_gap_height"
            :bg-color="$theme.cm_gap_color"
          ></u-gap>
        </view>
        <view style="width: calc(100% + 30px)">
          <form-section
            title="抽样取证物品"
            iconColorClass="u-success"
          ></form-section>
        </view>
        <u-form-item
          label="先保书"
          prop="fullDocNo"
          right-icon="arrow-right"
          :label-width="labelWidth"
        >
          <u-input
            placeholder="请选择先保书"
            input-align="right"
            :disabled="true"
            :clearable="false"
            v-model="sampleForm.fullDocNo"
            @click="
              () => {
                state.canEdit && clickDateBtn('goods');
              }
            "
          />
          <u-select
            :list="docGoodsList"
            v-model="isShowGoods"
            @confirm="confirmGoods"
          ></u-select>
        </u-form-item>
        <u-form-item label="抽样取证物品" :label-position="labelPosition">
          <view class="u-p-b-20" style="width: 100%;">
            <u-table font-size="26">
              <u-tr class="u-tr">
                <u-th class="u-th">
                  品种规格
                </u-th>
                <u-th width="30%" class="u-th">
                  包装形式
                </u-th>
                <u-th class="u-th">
                  抽样基数
                </u-th>
                <u-th class="u-th">
                  抽样数量
                </u-th>
                <u-th class="u-th">
                  样品情况
                </u-th>
              </u-tr>
              <u-tr class="u-tr" v-for="(item,index) in docGoodsSampledLst" :key="index">
                <u-td sclass="u-td">
                  {{ item.goodsName }}
                </u-td>
                <u-td width="30%" class="u-td">
                  <view>
                    <!-- @click="clickPackStyle(item)" -->
                    <u-input
                      :border="true"
                      :disabled="!state.canEdit"
                      placeholder=""
                      type="text"
                      v-model="item.packStyle"
                    >
                    </u-input>
                    <!-- <u-select :list="packOptions" :default-value="[defaultVal]" v-model="isShowPackSel" @confirm="packConfirm"></u-select> -->
                  </view>
                </u-td>
                <u-td class="u-td">
                  {{ item.qty }} {{ item.unit }}
                </u-td>
                <u-td class="u-td">
                  <u-form-item prop="handleQty" :border-bottom="false">
                    <u-input
                      type="text"
                      :disabled="!state.canEdit"
                      :border="true"
                      placeholder=""
                      v-model="item.handleQty"
                      @blur="onModifySampleQty(item)"
                    />
                  </u-form-item>
                </u-td>
                <u-td class="u-td">
                  <u-form-item :border-bottom="false">
                    <u-input
                      type="text"
                      :disabled="!state.canEdit"
                      :border="true"
                      placeholder=""
                      v-model="item.sampleSituation"
                    />
                  </u-form-item>
                </u-td>
              </u-tr>
            </u-table>
          </view>
        </u-form-item>
      </u-form>
    </view>
    <view class="submit-btns btn-other-cls" v-if="state.canEdit">
      <u-button plain class="u-btn" type="primary" @click="submitBtn('save')">
        保存
      </u-button>
      <u-button type="primary" class="u-btn" @click="submitBtn('submit')">
        提交
      </u-button>
    </view>
    <u-toast ref="uToast" />
		<!--抽样时间不可选择bug处理 fsx 2024-2-21 开始-->
    <u-picker
      mode="time"
      :params="paramsDate"
      v-model="isShowCheckS"
      @confirm="changeDate('sampleDate', $event)"
    >
    </u-picker>
		<!--抽样时间不可选择bug处理 fsx 2024-2-21 结束 -->
    <u-calendar
      mode="date"
      :max-date="yestDate"
      v-model="isShowDocDate"
      @change="changeDate('docDate', $event)"
    >
    </u-calendar>
    <u-popup mode="bottom" height="80%" v-model="partySelectShow">
      <select-party-component
        :params="partyParams"
        @choose="handlerChooseParty"
      ></select-party-component>
    </u-popup>
    <!-- 人员选择 -->
    <u-popup mode="bottom" height="80%" v-model="personSelectShow">
      <person-selection
        :params="psParam"
        @choose="handlerChoosePerson"
      ></person-selection>
    </u-popup>
    <dic-choice
      :keyWord="dicKeyWords"
      :currentSelect="dicCurrentSelect"
      v-model="dicShow"
      @confirm="selectDicConfirm"
    ></dic-choice>
  </view>
</template>

<script>
	import {
		DOC_STATUS,
	} from "@/common/common_enum.js";
	import moment from "moment";
	import caseCommon from "../caseCommonMixin.js";
	import officeService from "@/service/case/office.service.js";
	import caseService from "@/service/case/case.service";
	import {
		dateUtils,
	} from "@/common/util";
	import FormSection from "@/components/form-section.vue";
	import SelectPartyComponent from "../components/selectPartyComponent.vue";
	import PersonSelection from "@/pages/case/components/personSelection.vue";
  import fabButton from '@/components/uni-fab.vue';
	import DicChoice from "@/components/dic_choice.vue";
	import DicInput from "@/components/dic_input.vue";
	export default {
		components: {
			FormSection,
			SelectPartyComponent,
			PersonSelection,
    	DicChoice,
			DicInput,
			fabButton
		},
		mixins: [caseCommon, ],
		data() {
			return {
				moment,
				DOC_STATUS,
				paramsDate: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true,
					timestamp: true,
				},
				isRequired: true,
				errorType: ['border-bottom', 'message', ],
				labelWidth: '180',
				labelPosition: 'top',
				maxLength: 32700,
				content: '', // 提交保存弹窗提示内容
				isShowCheckS: false,
				rules: {
					party: [{
						required: true,
						message: '请选择当事人',
						trigger: ['change', 'blur', ],
					}, ],
					sampleDest: [{
						required: true,
						message: '请输入抽样目的',
						trigger: ['change', 'blur', ],
					}, ],
					sampleDate: [{
						required: true,
						message: '请选择抽样时间',
						trigger: ['change', 'blur', ],
					}, ],
					deliveryAddr: [
						{
							required: true,
							message: "请输入送达地点",
							trigger: ["change", "blur",],
						},
					],
					deliveryStyle: [
						{
							required: true,
							message: "请选择送达方式",
							trigger: ["change", "blur",],
						},
					],
					samplingFun: [
						{
							required: true,
							message: "请选择抽样方法",
							trigger: ["change", "blur",],
						},
					],
					address: [{
						required: true,
						message: '请输入抽样地点',
						trigger: ['change', 'blur', ],
					}, {
						max: 200,
						message: '抽样地点长度请输入200个字符之间！',
						trigger: 'change',
					}, ],
					// 承办人
					undertaker: [{
						required: true,
						message: '请选择承办人',
						trigger: ['change', 'blur', ],
					}, ],
					// 日期
					docDate: [{
						required: true,
						message: '请选择文书日期',
						trigger: ['change', 'blur', ],
					}, ],
				},
				sampleForm: {},
				preParams: {}, // 上个页面传过来的参数
				employeeLst: [],
				docGoodsSampledLst: [], // 抽样取证物品表数据
				docGoodsList: [], // 先保书下拉框数据
				defaultVal: 0,
				goodsDtlUuid: '', // 修改table某一行的uuid
				packOptions: [{
						label: '条盒软盒',
						value: '条盒软盒',
					},
					{
						label: '条盒硬盒',
						value: '条盒硬盒',
					}, {
						label: '不规则',
						value: '不规则',
					},
				],
				dicShow: false, // dic_select 是否显示
				dicKeyWords: "", // dic 关键字
				dicCurrentSelect: "", // dic 当前选择项
				isShowDocDate: false,
				yestDate: this.$u.timeFormat(Date.now()),
				doc: {},
				personSelectShow: false,
				partyList: [], // 当事人列表
				partyParams: {}, // 传给当事人选择页面的参数
				psParam: {
					min: 2,
					max: 2,
				},
				partySelectShow: false,
				isPerson: false,
				isShowGoods: false,
				isShowPackSel: false, // 抽样取证物品包装形式下拉框显示
				fContent: [{
					iconPath: require('@/static/oview.png'),
					selectedIconPath: require('@/static/oview.png'),
					text: '预览',
					active: false,
				}],
				fContents: [{
					iconPath: require('@/static/dy.png'),
					selectedIconPath: require('@/static/dy.png'),
					text: '打印',
					active: false,
				}],
				// h5端部分浏览器input设置disabled后点击事件失效 2023-10-27 fsx start
				pointerStyle: {
				  marginRight: "5px",
					pointerEvents: "none !important"
				},
				// h5端部分浏览器input设置disabled后点击事件失效 2023-10-27 fsx end
			}
		},
		watch: {
			isShowCheckS(newValue, oldValue) {
				this.$refs.changeRefS.validation();
			},
			isPerson(newValue, oldValue) {
				this.$refs.personChangeRef.validation();
			},
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		onLoad(preParams) {
			this.caseParam = this.getRouteParam();
			this.psParam.caseUuid = this.caseParam.caseUuid;
		},
		mounted() {
			this.docStep((docInfo) => {
				this.doc = docInfo;
				this.setRightBtns();
			});
			this.initDocData();
			this.getDoodsRegs();
		},
		methods: {
    // 数据字典组件选择事件
    dicSelectOpen: function (keyWord) {
      if (this.dicKeyWords == keyWord && this.dicShow) {
        return true;
      }
      return false;
    },
    showDic: function (key, cur, fileName) {
      if (this.dicShow) return;
      this.dicKeyWords = key;
      this.dicCurrentSelect = cur;
      this.dicShow = true;
    },
    selectDicConfirm: function (e) {
      // 类型
      if (this.dicKeyWords == this.$u.dic.DIC_KEYS.BSC_SERVICE_TYPE) {
        this.sampleForm.deliveryStyleName = e[0].label;
        this.sampleForm.deliveryStyle = e[0].extra.bcbCode;
      }
      if (this.dicKeyWords == this.$u.dic.DIC_KEYS.SAMPLE_STYLE) {
        this.sampleForm.samplingFunName = e[0].label;
        this.sampleForm.samplingFun = e[0].extra.bcbCode;
      }
    },
			docSub(flag) {
				if (flag) {
					console.log(flag)
					this.personSelectShow = true
					// this.psParam.caseUuid =  this.caseParam.caseUuid;
					this.psParam = {
						min: 2,
						caseUuid: this.caseParam.caseUuid,
					}
				}
			},
			// 初始化文书信息
			initDocData() {
				this.$u.loading('加载中...');
				officeService.docFields(this.caseParam.docUuid, true).then(docConfigs => {
					if (docConfigs.success) {
						this.docFields = [...docConfigs.data, ];
						// 获取勘验笔录信息参数
						let parms = {
							id: this.caseParam.id,
							docUuid: this.caseParam.docUuid,
							bizUuid: this.caseParam.bizUuid,
						}
						officeService.docSampleHandleNoticeApprove(parms).then(res => {
							this.$u.hideLoading();
							let [tiInfo, rs, ] = [{}, {}, ];
							if (res.success && res.data.length === 2) {
								tiInfo = res.data[0];
								rs = res.data[1];
								Object.keys(tiInfo).forEach(key => {
									rs[key] = tiInfo[key];
								});
							} else {
								rs = res.data[0];
							}
							this.sampleForm = rs;
							this.docGoodsSampledLst = rs.goods ? rs.goods : [];
							if (this.docGoodsSampledLst.length == 0) {
								this.getListByGoodsRegUuid();
							}
							this.getPartyInfoList();
						}).catch(er => {
							console.log(er);
							this.$u.hideLoading();
							this.$u.toast(er);
						});
					} else {
						this.$u.toast(docConfigs.msg);
					}
				}).catch(er => {
					console.log(er);
					this.$u.hideLoading();
					this.$u.toast(er);
				});
			},
			// 获取当事人list（多选）
			getPartyInfoList() {
				caseService.getPartyInfoList(this.caseParam.bizUuid).then(res => {
					if (!res.success) return;
					this.partyList = res.data.length > 0 ? res.data : [];
					this.partyList.forEach(itm => {
						if (this.sampleForm.partyUuids.indexOf(itm.partyUuid) != -1) {
							itm.checked = true;
						}
					});
					this.partyParams = {
						list: this.partyList,
						selUsersStr: this.sampleForm.partyUuids,
					}
				}).catch((err) => {
					this.partyList = [];
					console.log(err);
				});
			},
			// 选择当事人回调事件
			handlerChooseParty(e) {
				this.partySelectShow = false;
				this.sampleForm.party = e.partyNames;
				this.partyParams.selUsersStr = e.partyUuids;
				this.sampleForm.partyUuids = e.partyUuids;
			},
			// 设置右侧标题
			setRightBtns() {
				// #ifdef H5-DINGDING
				this.$deviceApi.setRight(this.state.canEdit ? '预览' : '打印', () => {
					this.printOrDown(this.state.canEdit);
					this.setRightBtns();
				}, true, true);
				// #endif
			},
			fabtrigger(btn) {
				if (btn.index == 0) {
					this.printOrDown(this.state.canEdit);
				}
			},
			// 打印/预览
			printOrDown(flag) {
				if (flag) {
					// 调接口预览
					this.submitBtn('preview');
				} else {
					this.downloadFile(this.doc.pdfFileId);
				}
			},
			downloadFile(fileId, titleName, isDownload) {
				let pdfIds = fileId;
				if (!pdfIds) {
					this.$u.toast("没有文书");
					return;
				}
				this.setRouteParam({
					fileId: pdfIds,
					fileName: titleName,
					isDownload: isDownload,
				});
				this.$u.route('pages/commonPage/printerComponent');
			},
			/**
			 * 设置抽样物品数量初始化为0
			 * @param goodsList
			 */
			docGoodsSampledTLInit(goodsList) {
				let docGoodsSample = [];
				goodsList.forEach((item, index) => {
					// 下拉框默认值显示处理
					this.packOptions.forEach((pack, packIndx) => {
						if (item.packStyle == pack.value) {
							item['defaultVal'] = packIndx;
						}
					});
					// 物品数量初始化
					if (item.handleQty) item.handleQty = '0';
					item.baseQty = item.qty;
					docGoodsSample.push(item);
				});
				this.docGoodsSampledLst = docGoodsSample;
			},
			// 点击选择包装形式
			clickPackStyle(item) {
				this.isShowPackSel = true;
				this.goodsDtlUuid = item.goodsDtlUuid;
				this.defaultVal = item.defaultVal;
			},
			packConfirm(e) {
				e.map((val, index) => {
					this.docGoodsSampledLst.forEach((item, index) => {
						if (item.goodsDtlUuid == this.goodsDtlUuid) {
							item.packStyle = val.label;
						}
					});
				});
			},
			/**
			 * 抽样数量 输入数量处理
			 * @param goods
			 */
			onModifySampleQty(goods) {
				let reg = new RegExp('^\\d+(\\.\\d+)?$');
				if (goods.handleQty != '') {
					// 验证输入的抽样数量是否正确
					if (!reg.test(String(goods.handleQty))) {
						this.showToast("请输入数字！");
						goods.handleQty = '0';
					} else {
						if (Number(goods.handleQty) > 999999) {
							this.showToast("超出最大抽样数量!");
							goods.handleQty = '0';
							return;
						}
						let jy = new Intl.NumberFormat(["cn-ZH", ], {
							style: "decimal",
							maximumFractionDigits: 2,
						});
						let temp = jy.format(Number(goods.handleQty));
						temp = temp.replace(/,/g, "");
						goods.handleQty = temp;
					}
				} else {
					goods.handleQty = '0';
				}
				if (Number(goods.handleQty) > Number(goods.qty)) {
					this.showToast("抽样数量不能大于样品基数！");
					goods.handleQty = '0';
					return;
				}
				// 该内容还未开发完
				if (Number(goods.handleQty) > 0) {
					this.docGoodsSampledLst.forEach((item, index) => {
						if (item.goodsDtlUuid == goods.goodsDtlUuid) {
							item.baseQty = item.qty;
							item.handleQty = Number(goods.handleQty).toFixed(1) + "";
							item.goodsSampleUuid = '';
						}
					});
				}
			},
			handlerChoosePerson(e) {
				this.personSelectShow = false;
				this.personList = [...e, ];
				let tIds = [];
				let tNames = [];
				this.personList.forEach(el => {
					tIds.push(el.personUuid);
					tNames.push(el.personName + "(" + el.leCertNo + ")");
				});
				this.sampleForm['undertakerUuids'] = tIds.join(",");
				this.sampleForm['undertaker'] = tNames.join(",");
			},
			updateBackState(param) {
				// 选择承办人回调函数
				if (param.personList) {
					this.employeeLst = param.personList;
				}
			},
			// 表单验证
			validForm() {
				let basicValid = false;
				this.$refs.uForm.validate(valid => {
					if (valid) {
						basicValid = true;
						console.log('表单验证通过');
					} else {
						basicValid = false;
						console.log('表单验证失败');
					}
				});
				return basicValid;
			},
			submitBtn(type) {
				// 点击提交、保存按钮
				let flag = this.validForm();
				// 校验表单
				if (flag) {
					// 校验抽样数量是否填写
					if (this.docGoodsSampledLst.length > 0) {
						let goodsLst = this.docGoodsSampledLst.filter(item => item.handleQty && item.handleQty != '0');
						if (goodsLst.length == 0) {
							this.showToast('请填写抽样数量!');
							return;
						}
					}

					if (type == 'submit') {
						this.$modal.confirm("完成后不可修改，请确认是否填写完整准确无误？", () => {
							this.submitDocInfo(type);
						});
					} else {
						this.submitDocInfo(type);
					}
				}
			},
			submitDocInfo(type) {
				// 调用保存、提交接口
				console.log(type);
				// 保存/提交
				let {
					id,
					docUuid,
					titemUuid,
				} = this.caseParam;
				this.sampleForm.caseUuid = this.caseParam.caseUuid;
				this.sampleForm.goods = this.docGoodsSampledLst;
				type == 'save' && this.$u.loading('数据保存中...');
				officeService.saveDocSampleHandleNotice(this.sampleForm, docUuid, titemUuid, id, this.caseParam.type)
					.then(
						res => {
							this.$u.hideLoading();
							if (res.success) {
								this.sampleForm = res.bean;
								try {
									if (!this.doc) this.doc = res.data[0];
								} catch (e) {
									console.log(e);
								}
								if (type == 'preview') {
									officeService.buildLocalPunish("/price/doc-sample-handle-notice", this.doc.docInsUuid).then(
										pdfId => {
											if (pdfId.success) {
												this.downloadFile(pdfId.bean, "预览", false);
											} else {
												this.$u.toast(pdfId.msg);
											}
										});
								} else if (type == 'submit') {

									this.$u.loading('数据提交中...');
									officeService.submitDocSampleHandleNotice(this.sampleForm, docUuid, titemUuid, id,
										this
										.caseParam.type).then(res => {
										this.$u.hideLoading();
										// this.saveBehaviorLog(1 , this.caseParam , this.doc);
										this.$u.toast(res.msg);
										if (res.success) {
											this.backPrev({
												paramKey: "offiList",
												param: {
													caseUuid: this.caseParam.bizUuid,
												},
											});
										}
									}).catch(er => {
										console.log(er);
										this.$u.hideLoading();
										this.$u.toast(er);
									});
								} else {
									// this.saveBehaviorLog(0 , this.caseParam , this.doc);
									this.$u.toast(res.msg);
								}
							} else {
								this.$u.hideLoading();
								this.$u.toast(res.msg);
							}
						})
			},
			clickDateBtn(type) {
				// 已完成、未开始、进行中状态是否可选日期、先保书
				type == 'time' ? this.isShowCheckS = true : this.isShowGoods = true;
			},
			confirmDate(e) {
				// 选择日期点击确认按钮事件
				this.sampleForm['sampleTime'] = this.$u.timeFormat(e.timestamp, 'yyyy-mm-dd hh:MM:ss');
			},
			changeDate(type, e) {
				this.sampleForm[type] =  this.$u.date(e.timestamp, 'yyyy年mm月dd日 hh时MM分')
			},
			showToast(title) {
				this.$refs.uToast.show({
					title: title,
					type: 'warning',
					icon: false,
				});
			},
			// 获取审批通过的先保书
			getDoodsRegs() {
				officeService.getDoodsRegs({
					caseUuid: this.caseParam.bizUuid,
				}).then((res) => {
					if (res.success) {
						this.handleGoodsSelect(res.data);
					}
				}).catch((err) => {
					this.$u.toast(err);
				});
			},
			// 获取物品清单
			getListByGoodsRegUuid() {
				let params = {
					caseUuid: this.caseParam.bizUuid,
					page: 1,
					limit: 1000,
				};
				if (this.sampleForm.goodsRegUuid) {
					params.goodsRegUuid = this.sampleForm.goodsRegUuid;
				}
				officeService.getListByGoodsRegUuid(params).then((res) => {
					if (res.success) {
						this.docGoodsSampledTLInit(res.data);
					}
				}).catch((err) => {
					this.$u.toast(err);
				});
			},
			// 先保书下拉框处理 先保书记录 等于0或大于1条，显示“请选择”，只有一条默认选中
			handleGoodsSelect(listItem) {
				let goodsArr = [{
					value: '',
					label: '全部',
				}, ];
				listItem.forEach((item, index) => {
					goodsArr.push({
						value: item.goodsRegUuid,
						label: item.fullDocNo,
					});
				});
				this.docGoodsList = goodsArr;
			},
			// 选择先保书之后展示物品信息
			confirmGoods(e) {
				e.map((val, index) => {
					this.sampleForm.fullDocNo = val.label;
					this.sampleForm.goodsRegUuid = val.value;
					this.getListByGoodsRegUuid();
				});
			},
		},
	}
</script>

<style lang="scss" scoped>
	@import "../case_common.scss";

	.u-td {
		height: auto;
		line-height: 20px;
	}

	.page {
		padding: 0;
	}
</style>
